<?php
//第一版
/*class Barbecuer{
    //烤肉串
    public function bakeMutton(){
        echo '烤肉串';
    }

    //烤鸡翅
    public function bakeChickenWing(){
        echo '烤鸡翅';
    }
}
//客户端调用
$barbecuer = new Barbecuer();
$barbecuer->bakeMutton();
$barbecuer->bakeMutton();
$barbecuer->bakeChickenWing();*/

//第二版
//抽象命令类
/*abstract class Command{
    protected $barbecuer;

    public function __construct($barbecuer)
    {
        $this->barbecuer = $barbecuer;
    }

    abstract public function excuteCommand();
}

//具体命令类
//烤羊肉串命令
class BakeMuttonCommand extends Command{
    public function excuteCommand()
    {
        $this->barbecuer->bakeMutton();
    }
}

class BakeChickenWingCommand extends Command{
    public function excuteCommand()
    {
        $this->barbecuer->bakeChickenWing();
    }
}

//服务员类
class Waiter{
    private $command;

    //设置订单
    public  function setOrder(Command $command){
        $this->command = $command;
    }

    public function notify(){
        $this->command->excuteCommand();
    }
}

class Barbecuer{
    //烤肉串
    public function bakeMutton(){
        echo '烤肉串';
    }

    //烤鸡翅
    public function bakeChickenWing(){
        echo '烤鸡翅';
    }
}
//客户端的实现
$barbcuer = new Barbecuer();
$bakeMutton1 = new BakeMuttonCommand($barbcuer);
$bakeMutton2 = new BakeMuttonCommand($barbcuer);
$bakeChickenWing = new BakeChickenWingCommand($barbcuer);
$waiter = new Waiter();

$waiter->setOrder($bakeMutton1);
$waiter->notify();
$waiter->setOrder($bakeMutton2);
$waiter->notify();
$waiter->setOrder($bakeChickenWing);
$waiter->notify();*/

//第三版
//服务员类
class Waiter{
    private $command = [];

    //设置订单
    public  function setOrder(Command $command){
        $this->command = $command;
    }

    public function notify(){
        $this->command->excuteCommand();
    }
}
